<? 
#####################################################
#  COPYRIGHT NOTICE
#####################################################
# In the following statements, the term "this 
# program" refers to all files associated with the
# execution and distribution of Adtrackz.
#
# This Program is Copyright 2004 Jonah Klimack.
# All Rights Reserved. 
#
# Selling the code for this program, modifying 
# and/or redistributing the code for this program
# in part or in whole over the Internet or in any 
# other medium is expressly forbidden. Violators
# will be prosecuted to the fullest extent of the law
# Copyright and header information may not be
# modified.
#
# This program is distributed "as is" and without 
# warranty of any kind, either express or implied.
# In no event shall the liability of Jonah Klimack 
# for any damages, losses and/or causes of 
# action exceed the total amount paid by the 
# user for this software.		
#####################################################
# DO NOT MODIFY ANYTHING IN THIS FILE
#####################################################



require "config.php";


if ($submit)
{
	list($user,$pass) = mysql_fetch_row(mysql_query("select username,password from adtrackz_login"));
	if ($user == $username && $pass == $password)
		do_login();
	else
		$error_msg = "<p class=alert>Username/Password are incorrect. Please try again.</p>";
}

require "header2.php";

if ($resend)
{
	list($user,$pass, $email) = mysql_fetch_row(mysql_query("select username,password, email from adtrackz_login"));
	//mail info
	$subject = "Your Adtrackz Login Information...";
	$message = "
Hello

As requested, Adtrackz has sent you your login Information.

Username: $user
Password: $pass

You can login at http://$domain/$udirectory/login.php

";

	mail($email,$subject,$message,"From: adtrackz@adtrackz.com\nReply-to: adtrackz@adtrackz.com\nX-Mailer: Adtrackz Mailer");

	echo "<p class=alert>Your login information has been sent to $email.</p>";
}

//get info from cookie if it exists
if ($_COOKIE['adtrackz_remember'])
{
	list ($username, $password) = explode ("|", $_COOKIE['adtrackz_remember']);
	$remember = "on";
}

if ($error_msg)
	error ($error_msg);

?>


<p class=heading>AdTrackzGold Login</p>



<p>Fill out this form to login. </p>

<form action="login.php" method="post">
<table width="500" border="0" cellspacing="0" cellpadding="5" align="center" bgcolor="white"  bordercolor="white">
<tr>
	<td valign="top">Username</td>
	<td valign="top">
		<input type="text" size="20" maxlength="25" name="username" value="<?=$username?>"> 		
	</td>
</tr>
<tr>
	<td valign="top">Password</td>
	<td valign="top">
		<input type="password" size="20" maxlength="25" name="password" value="<?=$password?>"> 		
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td>
		<? 
		if ($remember)
			$r_checked = "checked";
		?>
		Remember me <input type=checkbox name=remember <?=$r_checked?>></td>
</tr>
<tr>
	<td colspan=2 align=center>
	<input type="submit" name="submit" value="Login Now"  >
	</td>
</tr>
<tr>
	<td colspan=2>&nbsp;
	
	</td>
</tr>
  <tr align="center"> 
    <td colspan=2> <span class=small> <a href="login.php?resend=yes">Click here 
      if you forgot your login information</a> </span> </td>
</tr>
</table>


<?

require "footer.php";




function fetchUrl($url)
{
	// Set maximum number of seconds (can have floating-point) to wait for feed before displaying page without feed
	$numberOfSeconds=2;   

	// Suppress error reporting so Web site visitors are unaware if the feed fails
	error_reporting(0);

	// Extract resource path and domain from URL ready for fsockopen
	$url = str_replace("http://","",$url);
	$urlComponents = explode("/",$url);
	$domain = $urlComponents[0];
	$resourcePath = str_replace($domain,"",$url);

	// Establish a connection
	$socketConnection = fsockopen($domain, 80, $errno, $errstr, $numberOfSeconds);

	if (!$socketConnection) //didn't connect for whatever reason
	{
		return 0;
	}
	else    
	{
		$xml = '';
		fputs($socketConnection, "GET /$resourcePath HTTP/1.0\r\nHost: $domain\r\n\r\n");
		
		// Loop until end of file
		while (!feof($socketConnection))
			$xml .= fgets($socketConnection, 128);
		fclose ($socketConnection);

		return($xml);
	}	
}    


function do_login()
{
	global $username, $password, $domain, $udirectory;

	$url = "http://$domain/$udirectory/index.php";		
	$cvalue = "$username|$password";		

	if ($remember) //set 2 cookies, the usual one, plus one that tells us to remember login
	{
		$cookie = setcookie("adtrackz",$cvalue);
		$cookie = setcookie("adtrackz_remember",$cvalue, mktime( 0,0,0,12,31,2014));
	}
	else //set cookie to last this session only, turn off remember cookie
	{
		$cookie = setcookie("adtrackz",$cvalue);
		$cookie = setcookie("adtrackz_remember",$cvalue);
	}

	if (!$cookie)
	{
		$error_msg = "<p class=alert>You have cookies turned off. Please update your browser settings to accept cookies from this domain.</p>";
	}
	header("Location: $url");	
}


?>